package com.intretech.umsin.common.aop;

import com.intretech.umsin.common.service.ParseDictServiceFactory;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @version V1.0
 * @ClassName: DictAspect
 * @Description: 功能描述: 处理字典转换/码名映射
 * @author: 李启联
 * @date: 2022-05-30 23:24
 * @Copyright: Copyright (c) 2022
 */
@Aspect
@Component
@Slf4j
public class DictAspect {

    private ParseDictServiceFactory parseDictServiceFactory;

    public ParseDictServiceFactory getParseDictServiceFactory() {
        return parseDictServiceFactory;
    }

    public void setParseDictServiceFactory(ParseDictServiceFactory parseDictServiceFactory) {
        this.parseDictServiceFactory = parseDictServiceFactory;
    }

    public DictAspect(ParseDictServiceFactory parseDictServiceFactory) {
        this.parseDictServiceFactory = parseDictServiceFactory;
    }

    /**
     * 定义切点Pointcut
     */
    @Pointcut("execution(public * com.intretech.umsin..*.*Controller.*(..)) || @annotation(com.intretech.umsin.common.annotation.AutoDict)")
    public void excudeService() {
    }

    @Around("excudeService()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        Object result = joinPoint.proceed();
        return parseDictServiceFactory.createParseDictService().parseDictText(result);
    }


}
